<template>
  <list :list='list'></list>
</template>

<script>
import list from '@/components/List.vue'
export default {
  data(){
    return {
      list:[]
    }
  },
  components:{
    list
  },
    methods:{
        getContent(){
        let newID = this.$route.query.type
          console.log(newID);
        },
        getData(keyWord,url){
          // 请求数据get
          this.$axios({
                    url: 'https://cnodejs.org/api/v1/topics',
                    method: 'get',
                    params: {
                        'keyWord':keyWord,
                        'page': 1,
                        'pageSize': 20
                    }
                }).then(response => {
                  this.list = response.data.data;
                }).catch(error => {
                  console.log(error);
                })
        }
    },
    created(){
      if(this.$route.query.type === undefined){
        console.log('请求精品文章');
          this.getData('精品111');
        }else{
          console.log('请求文章' + this.$route.query.type)
          this.getData(this.$route.query.type);
        }
    },
    watch:{
        '$route'(to,from){
          if(this.$route.query.type === undefined){
            console.log('请求默认数据(精品)2处');
             this.getData('精品');
          }else{
            console.log(this.$route.query.type);
             this.getData(this.$route.query.type);
          }
            
        }
    }
}
</script>

<style>

</style>